package com.alibaba.otter.node.etl.load.loader.mq.rabbit.callback;

import com.alibaba.otter.node.etl.load.loader.mq.rabbit.exception.MqPluginException;
import com.alibaba.otter.node.etl.load.loader.mq.rabbit.exception.MqSerializeException;
import com.alibaba.otter.node.etl.load.loader.mq.rabbit.exception.MqUnexpectedException;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class DefaultFailureCallback implements PublishFailureCallback {

    @Override
    public void onSerializeFailure(Object message, Throwable e) {
        throw new MqSerializeException("消息序列化失败", null, null, e);
    }

    @Override
    public void onNoDestination(String exchange, String routingKey, Object message) {
        String msg = "没有对应的exchange[" + exchange + "]或routingKey[" + routingKey + "]，请检查配置";
        log.error(msg);
        throw new MqPluginException(msg);
    }

    @Override
    public void onNack(String exchange, String routingKey, Object message) {
        log.error("RabbitMQ Server内部异常, 消息投递失败: " + message);
    }

    @Override
    public void onUnexpectedError(Throwable cause) {
        throw new MqUnexpectedException("消息发送失败", cause);
    }
}
